﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title></title>
    <link rel="StyleSheet" href="/css/cms/main.css?<%=System.IO.File.GetLastWriteTime(Server.MapPath("/css/cms/main.css")) %>"  type="text/css" />
    <script src="/Scripts/common/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="/Scripts/common/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="/Scripts/common/util.js" type="text/javascript"></script>
    <script src="/Scripts/common/form.js?<%=System.IO.File.GetLastWriteTime(Server.MapPath("/Scripts/common/form.js")) %>" type="text/javascript"></script>
    <script type="text/javascript" src="/Scripts/cms/main.js?<%=System.IO.File.GetLastWriteTime(Server.MapPath("/Scripts/cms/main.js")) %>"></script>
    <script src="/Scripts/datepicker/js/jquery-ui-1.7.custom.min.js" type="text/javascript"></script>
    <link href="/Scripts/datepicker/css/smoothness/jquery-ui-1.7.custom.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="/Scripts/swfupload/handlers.js?<%=System.IO.File.GetLastWriteTime(Server.MapPath("/Scripts/swfupload/handlers.js")) %>"></script>
	<script type='text/javascript' src='/Scripts/autoseeklib/jquery.bgiframe.min.js'></script>
	<script type='text/javascript' src='/Scripts/autoseeklib/jquery.ajaxQueue.js'></script>
	<script type='text/javascript' src='/Scripts/autoseeklib/thickbox-compressed.js'></script>
	<script type='text/javascript' src='/Scripts/autoseeklib/jquery.autocomplete.js?<%=System.IO.File.GetLastWriteTime(Server.MapPath("/Scripts/autoseeklib/jquery.autocomplete.js")) %>'></script>
    <script type='text/javascript' src='/Scripts/cms/localdata.js?<%=System.IO.File.GetLastWriteTime(Server.MapPath("/Scripts/cms/localdata.js")) %>'></script>
	<link rel="stylesheet" type="text/css" href="/Scripts/autoseeklib/jquery.autocomplete.css" />
	<link rel="stylesheet" type="text/css" href="/Scripts/autoseeklib/thickbox.css" />
</head>
<% 
    IList list = (IList)ViewData["sectionlist"];
%>
<script language="JavaScript">
    var operator = { O_id: 0, O_Workid: "", O_Password: "", O_Remark: "", O_Createtime: new Date(), O_Rid: 0, O_DeleteFlag: 0};
    var mylist;
    var regular_input = {
        O_Workid: { exp: /^.{1,100}$/, m: "请输入用户名，20个字符以内" },
        O_Rid: { exp: /^[0-9]\d*$/, m: "请选择所属角色" }
    }
    var mainForm = "";
    $(document).ready(function () {
        //mainForm = $("#mainForm").html();
        mylist = new TurnPage("mylist");
        mylist.pageSize = 8;
        mylist.callback = function () { ajax(); };

        function ajax() {
            var param = { pagesize: mylist.pageSize, pageno: mylist.currPage };
            $.post("/system/getOperatorlist.html?" + (new Date()).getTime(), param, function (data) {
                data = $.evalJSON(data);
                if (mylist.currPage == 1) {
                    mylist.total = $.grep(data, function (n, i) { return typeof (n.total) == "number"; })[0].total;
                    data = $.grep(data, function (n, i) { return typeof (n.total) == "undefined"; });
                }
                loadDta(data);
            });
        }

        var loadDta = function (list) {
            var sp = [];
            var mapid;
            $("#mainTable tbody[name=mainlist]").html("");
            $.each(list, function (i, n) {
                sp.push('<tr>');
                sp.push('<td>' + n.O_Workid + '</td>');
                sp.push('<td>' + n.O_Remark + '</td>');
                sp.push('<td><a href="#mainForm" onclick="edit(' + n.O_id + ')" name="linkEdit" vid="' + n.O_id + '">修改</a>  <a href="#" onclick="del(' + n.O_id + ')" name="linkDel" >删除</a></td>');
                sp.push('</tr>');
            });
            $("#mainTable tbody[name=mainlist]").append(sp.join(''));
            //if (sp.length == 0) alert('没有符合条件的数据');
            $("#pager").html(mylist.getOutput());
        }
        $("input[name=buttSeek]").click(function () {
            mylist.currPage = 1;
            ajax();
        });
        $("input[name=buttReset]").click(function () {
            $("input[name=O_Workid]").val('');
            $("input[name=O_Remark]").val('');
            $("select[name=O_Rid]").val('');
            $("input[name=O_id]").val('0');
        });
        ajax();
        $("input[name=buttsend]").click(function () {
            if (!$.checkFormValid("mainForm")) return false;
            $.fillObj(operator, "#mainForm");
            $.post("/system/checkWorkid.html", { workid: $("#O_Workid").val(), id: operator.O_id }, function (d) {
                if (d == "0") {
                    $.post("/system/save.html", { operator: $.toJSON(operator) }, function (dta) {
                        alert("保存成功");
                        window.parent.frames["rightFrame"].location.reload();
                        ajax();
                    });
                }
                else {
                    alert("用户名重复");
                }
            });
        });
    })
        function edit(id) {
            $.post("/system/getOperatorbyid.html?" + (new Date()).getTime(), { res: id }, function (dta) {
                operator = $.evalJSON(dta);
                $.fillForm(operator, "#mainForm");
            });
            $("input[name=buttsend]").val('修改');
            $("input[name=O_Workid]").attr("readonly", "readonly"); //用户名不允许修改
    }
    function del(id) {
        if (confirm("是否确定")) {
            $.post("/system/delete.html?" + (new Date()).getTime(), { res: id }, function (dta) {
                location.reload();
            });
        }
    }
</script>
<body>
    <table cellspacing="0" id="seekForm">
        <tr>
            <th>
                用户名管理
            </th>
        </tr>
        <tr>
        <td>
                <input type="button" name="buttSeek" value="查询" onclick="" class="btn1" />
        </td>
        </tr>
    </table>
    <table id="mainTable" cellspacing="0">
        <caption style="color: red; font-size: 15px; font-weight: bold">管理员列表</caption>
        <tr>
            <th>
                用户名
            </th>
            <th>
                备注
            </th>
            <th>
            </th>
        <tbody name="mainlist">
        
        </tbody>
    </table>
    <div id="pager" class="pager">
    </div>
    <table cellspacing="0" id="mainForm">
        <tr>
            <th colspan="3">
                编辑用户
            </th>
        </tr>        
       <tr>
            <td>用户名*</td>
            <td><input id="O_Workid" name="O_Workid" /></td>
            <td><span class="tsxx"></span>初始密码为123456</td>
        </tr>
         <tr>
            <td>备注</td>
            <td><input id="O_Remark" name="O_Remark" /></td>
            <td><span class="tsxx"></span></td>
        </tr>
            <tr>
            <td>
                所属角色*
            </td>
            <td>
                <select id="O_Rid" name="O_Rid">
                <option value="">-请选择-</option>
                    <%
                        IList rList = (IList)ViewData["roleList"];
                        foreach (Hashtable hs in rList)
                        {
                            Response.Write("<option value=\"" + hs["R_id"] + "\">" + hs["R_Name"] + "</option>"); 
                        }
                     %>
                </select>
            </td>
            <td><input type="hidden" id="O_id" name="O_id" value="0" />
                <span class="tsxx"></span>
            </td>
        </tr>
        <tr class="main-status" id="mainstatus" style="display: none">
            <td colspan="3" class="bbd-bj-bom" align="center" height="41">
                正在验证表单....
            </td>
        </tr>
        <tr class="main-sub" id="mainsub">
            <td colspan="3" class="bbd-bj-bom" align="center" height="41">
                <input type="button" name="buttsend" class="btn1" style="width: 200px" 
                    value="新增" />
                <input type="button" name="buttReset" class="btn1" style="width: 200px" value="重置" />
            </td>
        </tr>
    </table>
</body>
</html>

